<?php
	header("Content-Type:text/html; charset=utf-8");
	session_start();
	if(empty($_SESSION["mb"]))
	{
		echo "0";//未登录
		return;
	}
	require_once("../connectMysql/connetMysql.class.php");
	$actid = $_POST['actid']; //获取actid
	$aplytype=$_POST['aplytype'];//获取报名参数
	$db=new connetMysql;
	$con=$db->getConnect();
	$applypost_sql="SELECT UserId FROM user WHERE UserPhone=".$_SESSION["mb"];		
	$result=mysqli_query($con,$applypost_sql);
	$row = mysqli_fetch_assoc($result);	
	$userid=$row["UserId"];
	
	$chk_sql="SELECT ActApplyId FROM actapply WHERE UserId=".$userid." AND ActivityId=".$actid;	
	mysqli_query($con,$chk_sql);
	$num=mysqli_affected_rows($con);
	if($num==0)
	{
		$inserapply_sql="INSERT INTO actapply(UserId,ActivityId) VALUES(".$userid.",".$actid.")";	
		mysqli_query($con,$inserapply_sql);
		$num2=mysqli_affected_rows($con);
		if($num2!=0)
		{
			echo "1";//报名成功
		}
		else
			echo "3";//已报名
		$db->clossConnet();
		
	}
	else if($aplytype==0&&$num!=0)
	{
		$delete_sql="DELETE FROM actapply WHERE UserId=".$userid." AND ActivityId=".$actid;	
		mysqli_query($con,$delete_sql);
		echo "4";//取消成功
	}
	else 
		echo "2";
	
?>